import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * 自定义一个类加载器
 */
public class MyClassLoader extends ClassLoader {

  /*  private String classPath;

    public MyClassLoader(String classPath) {
        this.classPath = classPath;
    }*/

    @Override
    protected Class<?> findClass(String classPath, String name) {
        byte[] cLassBytes = null;
        Path path = null;
        try {
            path = Paths.get(new URI(classPath));
            cLassBytes = Files.readAllBytes(path);
        } catch (URISyntaxException | IOException e) {
            e.printStackTrace();
        }
        assert cLassBytes != null;
        return defineClass(name, cLassBytes, 0, cLassBytes.length);
    }
}
